import { request, http } from '.'

/*
我的
*/

interface IPageNation {
	page: number
	pageSzie: number
}

export const accountLogin = async (data: { username: string, loginPassword: string}) => { // 根据账户密码登录
	return http('/api/v1/user/login', 'POST', data)
}

export const getUserAgreement = async () => { // 获取用户协议
	return http('/api/v1/dictionary/key/user-agreement', 'GET', {})
}

export const AppDescription = async () => { // APP介绍
	return http('/api/v1/dictionary/key/introduction', 'GET', {})
}

export const getPolicy = async () => { // 获取隐私政策
	return http('/api/v1/dictionary/key/privacy-policy', 'GET', {})
}


export const assetsInfo = async () => { // 资产查询
	return request('/api/v1/assets/info', 'GET', {})
}

export const goldenBeanList = async () => { // 金豆列表查询
	return request('/api/v1/recharge/activity/list', 'GET', {})
}



export const rechargeActivityList = async () => { // 金豆充值列表
	return request('/api/v1/recharge/activity/list', 'GET', {})
}


export const rechargeActivityBuy = async (data: {id: number, payType: number}) => { // 金豆充值
	return request(`/api/v1/recharge/activity/buy/${data.id}`, 'POST', {payType: data.payType})
}

export const paymentDeposit = async (data: {id: number, payType: number, payPassword: string}) => { // 支付体验押金
	return request(`/api/v1/orders/detail/${data.id}/deposit/pay`, 'PUT', {payType: data.payType, payPassword: data.payPassword})
}

export const refundMoney = async (id: number) => { // 申请退体验押金
	return request(`/api/v1/orders/detail/${id}/deposit/return`, 'PUT', {})
}




export const rechargeAgreement = async () => { // 充值协议
	return http('/api/v1/dictionary/key/user-recharge-policy', 'GET', {})
}

export const orders = async (data: Object) => { // 订单列表
	return request('/api/v1/orders', 'GET', data)
}

export const cancelOrders = async (payCode: string) => { // 取消订单
	return request(`/api/v1/pay/${payCode}/cancel`, 'PUT', {})
}

export const uploadAvarta = async (data: {portrait: string}) => { // 上传/更新头像
	return request('/api/v1/user/update/portrait', 'PUT', data)
}


export const getUserDetail = async () => { // 根据token获取用户信息
	return request('/api/v1/user/detail', 'GET', {})
}
export const logout = async () => { // 退出登录
	return request('/api/v1/user/logout', 'POST', {})
}

export const setNickName = async (data: {nickName: string}) => { // 修改昵称
	return request('/api/v1/user/update/nickname', 'PUT', data)
}

export const getCodeLoadingPassword = async (phone: string) => { // 获取验证码（设置登陆密码）
	return request(`/api/v1/verifycode/loginpassword/phone/${phone}`, 'POST', {})
}


export const getCodePaymentPassword = async () => { // 获取验证码（设置支付密码）
	return request(`/api/v1/verifycode/paymentpassword/phone`, 'POST', {})
}

export const updatePaymentPassword = async (data: { // 更新支付密码
	"confirmPaymentPassword": string,
	"paymentPassword": string,
	"verificationCode": string
}) => { 
	return request(`/api/v1/user/paymentpassword`, 'PUT', data)
}

export const updateLoadingPassword = async (data: { // 更新登陆密码
	"loginPassword": string,
	"confirmLoginPassword": string,
	"verificationCode": string,
	"phone": string
}) => { 
	return request(`/api/v1/user/loginpassword`, 'PUT', data)
}


export const getOrderList = async (data: { // 获取订单列表
	page: number,
	pageSize: number,
	orderStatus: number,
	payStatus: number
}) => { 
	return request(`/api/v1/orders`, 'GET', data)
}


export const orderDetail = async (id: number) => { // 订单详情
	return request(`/api/v1/orders/${id}`, 'GET', {})
}

export const reservationList = async <T>(data: T ) : Promise<any> => { // 预约列表
	return request(`/api/v1/orders/detail/list`, 'GET', data)
}

export const reservationDetail = async (id: number) => { // 预约详情
	return request(`/api/v1/orders/detail/${id}`, 'GET', {})
}


export const propertyChangeRecored = async <T>(data: T ) : Promise<any> => { // 资产变动
	return request(`/api/v1/assets/records`, 'GET', data)
}

export const rewardList = async (data: {page: number, pageSize: number} ) : Promise<any> => { // 获取收益列表
	return request(`/api/v1/assets/reward/list`, 'GET', data)
}

export const rewardProportion = async () : Promise<any> => { // 获取创客比例
	return request(`/api/v1/maker/setting`, 'GET', {})
}


export const reservationUse = async (data: { // 预约使用
	appointmentTime: string,
	appointmentRemark: string
	id: number
}) : Promise<any> => { 
	return request(`/api/v1/orders/detail/${data.id}/appointment`, 'PUT', {appointmentTime: data.appointmentTime, appointmentRemark: data.appointmentRemark})
}


export const updateUpgradePa =  async (data: {payType: number, payPassword: string}) => { // 申请成为创客
	return request(`/api/v1/user/update/upgradePay`, 'PUT', data)
}

export const queryWithdrawalList =  async (data: { // 查询可提现列表 status 1、已申请，2、已取消, 2、已拒绝，3、已完成
		page: number
		pageSize: number
		status: number | 1 | 2 | 3 | 4 
	}) => { 
	return request(`/api/v1/assets/withdraw/list`, 'GET', data)
}

export const WithdrawaApply =  async (data: { // 提现申请
		"bankInfoId": number,
		"balance": number
	}) => { 
	return request(`/api/v1/assets/withdraw`, 'POST', data)
}

export const editAddress =  async (data: { // 修改地址
		"id"?: number,
		"identity": string,
		"names": string,
		"phone": string,
		"Province"?: string,
		province: string
		"city": string,
		"prefecture": string,
		"street": string,
		"detail_address"?: string
		"default_flag": number
	} | any) => { 
	return request(`/api/v1/user/update/deliveryAddresses`, 'PUT', data)
}

export const createAddress =  async (data: { // 创建地址
		"names": string,
		"phone": string,
		"province"?: string,
		"city": string,
		"prefecture": string,
		"street": string,
		"defaultFlag": number
	}) => { 
	return request(`/api/v1/user/create/deliveryAddresses`, 'POST', data)
}


export const getAllAddress = async (data: IPageNation) => { // 获取收货地址列表
	return request(`/api/v1/user/deliveryAddresses/list`, 'GET', data)
}

export const getDefaultAddress = async () => { // 获取默认收货地
	return request(`/api/v1/user/deliveryAddresses/default`, 'GET', {})
}

export const getAddressDetail = async (id: number) => { // 获取收货地详情
	return request(`/api/v1/user/deliveryAddresses/${id}`, 'GET', {})
}


export const delAddress = async (id: number) => { // 删除收货地
	return request(`/api/v1/user/deliveryAddresses/${id}`, 'DELETE', {})
}

export const createBankCard =  async (data: { // 添加银行卡
		"cardholder": string,
		"bank": string,
		"bankCardNumber": string,
		"bankOfDeposit": string
	}) => { 
	return request(`/api/v1/user/create/withdrawinfo`, 'POST', data)
}

export const getAllBank = async (data: IPageNation) => { // 获取银行卡列表
	return request(`/api/v1/user/withdrawinfo/list`, 'GET', data)
}

export const delBank = async (id: number) => { // 删除银行卡
	return request(`/api/v1/user/withdrawinfo/${id}`, 'DELETE', {})
}

export const editBank =  async (data: { // 编辑银行卡
		"id"?: number,
		"identity"?: string,
		"cardholder": string,
		"bank": string,
		"bankCardNumber": string,
		"bankOfDeposit": string
	}) => { 
	return request(`/api/v1/user/update/withdrawinfo`, 'PUT', data)
}

